<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="views/include :: header('团队信息')"/>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div style="padding-bottom: 10px;" id="LAY_lay_add" >
            <!--<div class="layui-input-inline" style="width: 200px;">
                <input type="text" name="title" id="title" placeholder="请输入团队名称" autocomplete="off"
                       class="layui-input">
            </div>
            <div class="layui-input-inline" style="width: 100px;">
                <button type="button" class="layui-btn layui-btn-normal" id="btn-search">
                    <i class="layui-icon layui-icon-search"></i> 搜索
                </button>
            </div>-->
            <table id="munu-table" class="layui-table" lay-filter="munu-table"></table>
        </div>
    </div>
</div>
<!-- 操作列 -->
<script type="text/html" id="auth-state">
    <a class="layui-btn layui-btn-danger  layui-btn-sm" lay-event="del"><i class="layui-icon">&#xe640;</i>退出此团队</a>
</script>


<script type="text/javascript">
    layui.use(['form','table','layer'], function () {
        const form = layui.form,
            layer = layui.layer,
            $ = layui.jquery,
            table = layui.table;

        $("#btn-search").click(function () {
            let title = $("#title").val();
            table.reload('munu-table', {
                where: {"title":title},
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });


        let tab_tab = table.render({
            elem: '#munu-table',
            url: '/teamMember/myJoin', //数据接口
            page: true,
            limit: 10,
            limits: [10, 20, 30],
            cols: [
                [
                    {title: "团队名称", field: "teamName",edit: 'text',align: "center"},
                    {title: "创建人", field: "createUser",edit: 'text',align: "center"},
                    {
                        title: "加入时间", field: "create_time",width: 180,  align: "center",
                        templet: function (d) {
                            if (d.updateTime != null) {
                                return layui.util.toDateString(d.updateTime);
                            }else if (d.create_time != null) {
                                return layui.util.toDateString(d.create_time);
                            }
                            return '';
                        }
                    },
                    {title: "操作", templet: '#auth-state',width: 250, align: 'center',}
                ]
            ]
        });


        //监听工具条
        table.on('tool(munu-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'del') {
                layer.confirm('确认退出此团队吗？', function (index) {
                    $.ajax({
                        url: '/teamMember/deleteOne',
                        data: {"teamMemberId":data.team_member_id},
                        type: 'post',
                        dataType: 'json',
                        success: function (data) {
                            if (data.code === 0) {
                                layer.msg(data.msg, {
                                    offset: '15px',
                                    icon: 6,
                                    time: 1000
                                }, function () {
                                    table.reload('munu-table', {
                                    });
                                });
                            } else {
                                layer.msg(data.msg, {
                                    icon: 5,
                                    time: 2000
                                });
                            }
                        }, error: function (data) {
                            layer.msg("操作失败", {time: 1000, icon: 5});
                        }
                    });
                });
            }
        });

        $('.layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

</script>
</body>
</html>